package com.example.demo;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RequestController {

    @RequestMapping("/request")
    public String request(HttpServletRequest request) {
        // 获取请求方法
        String method = request.getMethod();
        System.out.println(method);

        // 获取请求地址
        String url = request.getRequestURL().toString();
        System.out.println(url);
        String uri = request.getRequestURI();
        System.out.println(uri);

        // 获取请求协议
        String protocol = request.getProtocol();
        System.out.println(protocol);

        // 获取请求头
        String header = request.getHeader("User-Agent");
        System.out.println(header);

        // 获取请求参数
        String name = request.getParameter("name");
        System.out.println(name);
        String age = request.getParameter("age");
        System.out.println(age);

        return "200";
    };
}
